/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kedacom.demo.h2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Random;

/**
 *
 * @author xiaojinghai
 */
public class H2Test {

    public static void main(String[] args) throws Exception {
        //以嵌入式内存模式工作，建个简单的表
        //Connection conn = DriverManager.getConnection("jdbc:h2:mem:test");
        Connection conn = DriverManager.getConnection("jdbc:h2:file:data/test");
        PreparedStatement stmt = conn.prepareStatement("CREATE TABLE cc (GUID varchar(40) PRIMARY KEY,Data int,AddTime datetime)");
        stmt.execute();
        Random rand = new Random();

        long start = System.currentTimeMillis();
        stmt = conn.prepareStatement("INSERT INTO cc VALUES (RANDOM_UUID(), ?, NOW())");
        for (int i = 0; i < 100000; ++i) {
            stmt.setInt(1, rand.nextInt());
            stmt.execute();
        }
        long duration = System.currentTimeMillis() - start;
        conn.close();

        System.out.println("Finished in " + duration + " ms");
    }
}
